﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PaDgame;

namespace PaDgame
{
	public class UserGUI : MonoBehaviour
	{
		private IUserAction action;
		public int status = 0;
		bool ruleStatus = false;
		GUIStyle textStyle;
		GUIStyle buttonStyle;

		void Start()
		{
			action = SSDirector.getInstance().currentSceneController as IUserAction;

			textStyle = new GUIStyle();
			textStyle.fontSize = 30;

			buttonStyle = new GUIStyle("button");
			buttonStyle.fontSize = 15;
		}
		void OnGUI()
		{
			if (GUI.Button(new Rect(10, 10, 60, 30), "Rule", buttonStyle))
			{
				if (ruleStatus)
                {
					ruleStatus = false;
                }
                else
                {
					ruleStatus = true;
				}
			}
			if (ruleStatus)
			{
				GUI.Label(new Rect(Screen.width / 2 - 150, 10, 200, 50), "帮助所有牧师和恶魔渡河");
				GUI.Label(new Rect(Screen.width / 2 - 150, 30, 200, 50), "红色方块为魔鬼，紫色球体为牧师");
				GUI.Label(new Rect(Screen.width / 2 - 150, 50, 200, 50), "点击牧师、恶魔或船进行移动");
				GUI.Label(new Rect(Screen.width / 2 - 150, 70, 200, 50), "船上至少要有一个人驾驶其渡河");
				GUI.Label(new Rect(Screen.width / 2 - 150, 90, 400, 50), "若在河的一边恶魔数量多于牧师数量，牧师会被杀死，游戏失败");
			}
			
			if (status == 1)
			{
				GUI.Label(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 100, 100, 50), "You lose!", textStyle);
				if (GUI.Button(new Rect(Screen.width / 2 - 70, Screen.height / 2 - 60, 100, 50), "Restart", buttonStyle))
				{
					status = 0;
					action.restart();
				}
			}
			else if (status == 2)
			{
				GUI.Label(new Rect(Screen.width / 2 - 80, Screen.height / 2 - 100, 100, 50), "You win!", textStyle);
				if (GUI.Button(new Rect(Screen.width / 2 - 70, Screen.height / 2 - 60, 100, 50), "Restart", buttonStyle))
				{
					status = 0;
					action.restart();
				}
			}
		}
	}

	public class ClickGUI : MonoBehaviour
	{
		IUserAction action;
		MyCharacterController chCtrl;

		public void setController(MyCharacterController chCtrl)
		{
			this.chCtrl = chCtrl;
		}

		void Start()
		{
			action = SSDirector.getInstance().currentSceneController as IUserAction;
		}

		void OnMouseDown()
		{
			if (gameObject.name == "boat")
			{
				action.moveBoat();
			}
			else
			{
				action.clickCharacter(chCtrl);
			}
		}
	}
}